<%-- 
    Document   : daadd
    Created on : 2024年3月31日, 上午9:24:50
    Author     : JUST
--%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <%
            String msg;
            request.setCharacterEncoding("utf-8");
            String name = request.getParameter("name");
            String age = request.getParameter("age");
            String birthday = request.getParameter("birthday");
            String salary = request.getParameter("gongzi");
            
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager
                    .getConnection("jdbc:mysql://dusin.top:3306/jsp?useUnicode=true&characterEncoding=utf8"
                            ,"jsp","jsp123");
            String sql = "insert into person(name,age,birthday,salary) values(?,?,?,?)";
            PreparedStatement pst = connection.prepareStatement(sql);
            pst.setString(1, name);
            pst.setString(2, age);
            pst.setString(3, birthday);
            pst.setString(4, salary);
            int rows = pst.executeUpdate();
            if(rows>0){
                msg = "插入成功";
            }else{
                msg = "插入失败";
            }
            pst.close();
            connection.close();
            
            response.setHeader("refresh", "5;URL=ShowAllPersons.jsp");
        %>
    </head>
    <body>
        
        <h1><%= msg%>！！</h1>
    </body>
</html>
